@tool
@icon("icons/transition.svg")
class_name Transition
extends Node

@export_node_path("State") var to:NodePath
# 暂时没用到
@export var event:StringName = ""
@export var guard:Guard
@export var delay_seconds:float = 0.0
@export var active:bool = true

var has_event:bool:
	get:
		return event != null and event.length() > 0

func evaluate_guard() -> bool:
	if guard == null:
		return true
	var parent_state = get_parent()
	if parent_state == null or not parent_state is State:
		push_error("Transition is must be children of State.")
		return false
	var to_state:State = get_node_or_null(to)
	if not to_state:
		return false
	return guard.is_satisfied(self,parent_state) and to_state.get_state_status() == GameEnum.StateStatus.Ready
func resolve_target() -> State:
	if to == null or to.is_empty():
		return null
	var result = get_node_or_null(to)
	if result is State:
		return result
	return null

func _get_configuration_warnings() -> PackedStringArray:
	var warning:Array = []
	if not to:
		warning.append("至少需要一个目标状态")
	var temp_state = get_node_or_null(to)
	if not temp_state:
		warning.append("目标状态找不到")
	elif temp_state == get_parent():
		warning.append("目标状态不能是当前状态")
	return warning
